package com.gp.pj.controller;


import com.alibaba.fastjson.JSONObject;
import com.gp.pj.entity.Employee;
import com.gp.pj.service.EmployeeService;
import com.gp.pj.utils.ResultCode;
import com.gp.pj.utils.ResultUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Chloe
 * @since 2020-12-07
 */
@RestController
@RequestMapping("/")
public class EmployeeController {

    @Resource
    EmployeeService employeeService;

    @ResponseBody
    @GetMapping(value = "/getStudentList")
    public ResultUtils studentList() {
        return employeeService.getStudentList();
    }

    @ResponseBody
    @PostMapping(value = "/updateStudent")
    public ResultUtils updateStudent(@RequestBody JSONObject jsonRe){
        Employee employee = jsonRe.toJavaObject(Employee.class);
        boolean b = employeeService.updateById(employee);
        if (b) {
            return ResultUtils.success();
        } else {
            return ResultUtils.failure("更新学生信息失败");
        }
    }

    @ResponseBody
    @GetMapping(value = "/getTeacherList")
    public ResultUtils teacherList() {
        return employeeService.getTeacherList();
    }

    @ResponseBody
    @PostMapping(value = "/updateTeacher")
    public ResultUtils updateTeacher(@RequestBody JSONObject jsonRe){
        Employee employee = jsonRe.toJavaObject(Employee.class);
        boolean b = employeeService.updateById(employee);
        if (b) {
            return ResultUtils.success();
        } else {
            return ResultUtils.failure("更新教师信息失败");
        }
    }

}
